package com.yitiao.multithread.case06;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * <h3>线程池提交任务</h3>
 * <p>execute：返回空，不会抛出异常,也不会继续执行</p>
 * <p>submit：返回future对象，会抛出异常</p>
 */
public class ThreadExecutorDemo {
    public static void main(String[] args) {
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
                1,
                1,
                1,
                TimeUnit.SECONDS, new ArrayBlockingQueue<>(1000));

        threadPoolExecutor.submit(new Runnable() {
            @Override
            public void run() {
                int i = 10/0;
                System.out.println("this is submitTask");
            }
        });
        threadPoolExecutor.execute(new Runnable() {
            @Override
            public void run() {
                int i = 10/0;
                System.out.println("this is executeTask");
            }
        });

        threadPoolExecutor.shutdown(); // 如果不关闭线程池，主线程不会结束
    }
}
